//
//  HomeViewController.swift
//  YUANSHI
//
//  Created by pro on 2019/12/7.
//  Copyright © 2019 wangbin. All rights reserved.
//

import UIKit
import SnapKit

class HomeViewController: WBBaseViewController,noLoginViewDelegate {
    
    
    
    lazy var noLoginView:NoLoginView={
        
        let noLoginView = NoLoginView.init();
        noLoginView.backgroundColor = UIColor.black;
        return noLoginView;
        
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "账本";
        self.navigationController?.navigationBar.barTintColor = UIColor.black;
        self.view.backgroundColor = UIColor.black;
        
        setNaviationBut();
        
        //未登录状态
        setNoLoginUI();
        
    }
    
    func setNoLoginUI()  {
        
        self.noLoginView.gotoDeleaget = self;
        self.view.addSubview(self.noLoginView);
        noLoginView.snp.makeConstraints { (make) in
            make.center.equalToSuperview();
            make.width.height.equalToSuperview();
        };
    }
    
    func gotoLoginView() {
        
        let loginVc = LoginMainViewController();
        self.navigationController?.pushViewController(loginVc, animated: true);
        
    }
    
    func setNaviationBut(){
        
        let leftBarItem = UIBarButtonItem(image: UIImage.init(named: "bx_market_add")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(leftButtonClick));
        self.navigationItem.leftBarButtonItem = leftBarItem;
        
        let rightBarItem = UIBarButtonItem(image: UIImage.init(named: "bx_opsition_apikey")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(rightButtonClick));
        self.navigationItem.rightBarButtonItem = rightBarItem;
        
        
    }
    
    @objc func leftButtonClick() {
        
    }
    
    @objc func rightButtonClick()  {
        
    }
    
    
}



@objc protocol noLoginViewDelegate {
    func gotoLoginView();
}

class NoLoginView: UIView {
    
    weak var gotoDeleaget : noLoginViewDelegate?;
    
  
    lazy var backImageView = UIImageView.init(image: UIImage.init(named: "bx_manual_tip")?.withRenderingMode(.alwaysOriginal));
    lazy var contLabel: UILabel = {
        let contLabel = UILabel.init();
        contLabel.text = "科技赋能交易 让量化在简单些";
        contLabel.textColor = UIColor.white;
        return contLabel;
    }();
    
    lazy var conntLabel2:UILabel = {
        let conntLabel2 = UILabel.init();
        conntLabel2.text = "年化收益率超100%";
        conntLabel2.alpha = 0.6;
        conntLabel2.textColor = UIColor.white;
        return conntLabel2;
    }()
    
    lazy var loginBtn : UIButton = {
        
        let loginbtn  = UIButton.init();
        loginbtn.setTitle("立即登录", for: .normal);
        loginbtn.backgroundColor = UIColor.yellow;
        loginbtn.layer.masksToBounds = true;
        loginbtn.layer.cornerRadius = 5;
        loginbtn.setTitleColor(UIColor.black, for: .normal);
        loginbtn.addTarget(self, action:#selector(gotoLogin) , for: .touchUpInside);
        return loginbtn;
    }();
    
    lazy var contLabel3 : UILabel = {
        
        let contlabel3 = UILabel.init();
        contlabel3.text = "支持200+交易所和5000+种数字交易币";
        contlabel3.alpha = 0.6;
        contlabel3.textColor = UIColor.white;
        contlabel3.font = UIFont.systemFont(ofSize: 12);
        return contlabel3;
    }();
    
    override init(frame: CGRect) {
        super.init(frame: frame);
//        self.gotoDeleaget = gotoDeleaget;
       
        setNoLoginUI();
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

    
    @objc func gotoLogin() {
        
        self.gotoDeleaget?.gotoLoginView();
        
    }
    func setNoLoginUI()  {
        
        self.addSubview(backImageView);
        backImageView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview();
            make.top.equalTo(self.top).offset(40);
        }
        
        self.addSubview(self.contLabel);
        self.contLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(backImageView);
            make.top.equalTo(backImageView.snp_bottom).offset(20);
        }
        
        self.addSubview(self.conntLabel2);
        self.conntLabel2.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.contLabel);
            make.top.equalTo(self.contLabel.snp_bottom).offset(10);
        }
        self.addSubview(self.loginBtn);
        loginBtn.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview();
            make.top.equalTo(self.conntLabel2.snp_bottom).offset(40);
            make.width.equalTo(kSCREEN_WIDTH-20);
            make.height.equalTo(50);
        }
        
        self.addSubview(self.contLabel3);
        contLabel3.snp.makeConstraints { (make) in
            
            make.centerX.equalToSuperview();
            make.top.equalTo(self.loginBtn.snp_bottom).offset(10);
        }
    }
    
    
}
